<?php


namespace app\common\controller;


use RequestContext;

class UserBaseController extends BaseController
{

    function check_acl()
    {
        $acl = [
            'user_type' => OPER_TYPE_USER,
            'modules' => [
                MODULE_USER => '77',
            ],
        ];
    }

    /*
     * 检查token
     * */
    function check_token()
    {
        $user_info = null;

        if ($this->argv['token'] == 'SUOZHANGBIEKAIQIANG'){
            $user_info =[
              'user_type' => OPER_TYPE_OPS,
              'id' => 'SYSTEM',
              'name' => '系统',
              'phone' => '9527',
              'channel' => 'SYSTEM'
            ];
        } else{
          $user_info = (new \UserToken())->query_info($this->argv['token']);
        }

        if (empty($user_info)){
            $this->throw_myexception(E_TOKEN_ERROR,'校验TOKEN失败');
        }

        if (!empty($this->argv['user_coordinate'])){
            $user_info['user_coordinate'] = [floatval($this->argv['user_coordinate'][0]),floatval($this->argv['user_coordinate'][1])];
        }else{
            $user_info['user_coordinate'] = null;
        }

        \ApiOper::instance()->_user_info = $user_info;
        $this->user_info = $user_info;
        RequestContext::$opid = $user_info['id'];
        \ApiOper::instance()->set_token($this->argv['token']);

        if (isset($user_info['city_id'])){
            $this->city_id = $user_info['city_id'];
        }

        if (empty($this->city_id) && isset($this->argv['city_id'])){
            $this->city_id = $this->argv['city_id'];
        }
    }
}